package com.lanou.moving.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import android.widget.Toast;

import com.lanou.moving.R;
import com.lanou.moving.eventBus.MyEventBus;
import com.lanou.moving.shake.ShakeDetector;

import de.greenrobot.event.EventBus;

/**
 * Created by 刘琪 on 15/11/3.
 */
public class ServiceReceiver extends BroadcastReceiver {
    public static final String NOTIFICATION_ITEM_BUTTON_LAST = "com.lanou.moving.receiver.ServiceReceiver.last";// ----通知栏上一首按钮
    public static final String NOTIFICATION_ITEM_BUTTON_PLAY = "com.lanou.moving.receiver.ServiceReceiver.play";// ----通知栏播放按钮
    public static final String NOTIFICATION_ITEM_BUTTON_NEXT = "com.lanou.moving.receiver.ServiceReceiver.next";// ----通知栏下一首按钮
    public static int status = 1;//播放状态(1:播放,2:暂停)

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        // 通知栏播放按钮响应事件
        if (action.equals(NOTIFICATION_ITEM_BUTTON_LAST)) {
            EventBus.getDefault().post(new MyEventBus.PlayControl(2));
        } else if (action.equals(NOTIFICATION_ITEM_BUTTON_PLAY)) {
            switch (status) {
                case 1:
                    EventBus.getDefault().post(new MyEventBus.PlayMusic(2));
                    status = 2;
                    break;
                case 2:
                    EventBus.getDefault().post(new MyEventBus.PlayMusic(3));
                    status = 1;
                    break;
            }
        } else if (action.equals(NOTIFICATION_ITEM_BUTTON_NEXT)) {
            EventBus.getDefault().post(new MyEventBus.PlayControl(3));
        }
    }
}
